package cn.dapeng.other;

/**
 * 阶乘
 */
public class SumOfFactorial {

    public static int m1(int n) {
        int sum = 0;
        for (int i = 2; i <= n; i++) {
            sum += m2(i);
        }
        return sum;
    }

    public static int m2(int n) {
        if (n == 1) return 1;
        int sum = 1;
        for (int i = 2; i <= n; i++) {
            sum += sum * i;
        }
        return sum;
    }

    public static int f1(int n) {
        int sum = 1, preSum;
        for (int i = 2; i <= n; i++) {
            preSum = sum * i;
            sum += preSum;
        }
        return sum;
    }

    public static void main(String[] args) {
        System.out.println(m1(3));
        System.out.println(f1(3));
    }
}
